home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ca29_3.zip / BBMAINT4.CMD < prev    next >
OS/2 REXX Batch file  |  1992-03-24  |  35KB  |  1,195 lines

  1. ;****    TRACE ON        ; Debugging
  2. ;
  3. ; ----- COM-AND BBS file maintenance script (MAIL file)
  4. ;    Commenced: 11/90 R.McG
  5. ; -----------------------------------------------------------------------
  6. ;    Purpose:
  7. ;       The script, named BBMAINT4.CMD, produces the main window for
  8. ;    Mail functions of BBMAINT, and implements its functions.  It is
  9. ;    not directly callable itself.
  10. ; -----------------------------------------------------------------------
  11. ;    Usage:
  12. ;       N99 -> Text attribute value (Setup by BBMAINT.CMD)
  13. ;       N98 -> BBMAINT Mainline cursor position
  14. ;       N97 -> BBMAINT Mainline cursor position
  15. ;       N96 -> our mainline cursor position
  16. ;       N95 -> our mainline cursor position
  17. ; -----------------------------------------------------------------------
  18. ;
  19. ;    This script is intended ONLY to be used for FCALL
  20. ;
  21.     IF NOT FCALLED
  22.        WOPEN 10,10,13,70 (cont) NOMAEsc
  23.        ATSAY 10,12 (cont) " BBS Mail "
  24.        ATSAY 11,12 (cont) " The script: "*"_SCRIPT"
  25.        ATSAY 12,12 (cont) " is not used by itself... it is called through BBMAINT"
  26.        ATSAY 13,26 (cont) " Press any key to continue "
  27.        ;
  28.        ;    Wait a keypress
  29.        ;
  30.        KEYGET S0        ; Wait for any key
  31.        WCLOSE        ; Close open window
  32.        EXIT         ; Terminate right here
  33.        ENDIF
  34.     GOSUB Mailfile        ; Invoke function
  35.     FRETURN         ; Return to caller
  36. ; -----------------------------------------------------------------------
  37. ; ----- NoMail:  Inform that there's no BBS-Mail file to modify
  38. ;
  39. NoMail:
  40.     WOPEN 10,10,13,70 (cont) NOMAEsc
  41.     ATSAY 10,12 (cont) " BBS MailDir "
  42.     ATSAY 11,12 (cont) " The file: "*S24&"\BBS-Mail"
  43.     ATSAY 12,12 (cont) " does not exist.  Please create subdirectories first."
  44.     ATSAY 13,26 (cont) " Press any key to continue "
  45.     ;
  46.     ;    Wait a keypress
  47.     ;
  48.     KEYGET S0        ; Wait for any key
  49.     WCLOSE
  50. NOMAEsc:
  51.     RETURN
  52. ; -----------------------------------------------------------------------
  53. ; ----- Subroutine: MailFile -> Update Mail directory
  54. ;
  55. MailFile:
  56.     GOSUB NewMail        ; Create if not there
  57.     IF NOT ISFILE S24&"\BBS-Mail"
  58.        GOSUB NoMail     ; Inform there's no file
  59.        RETURN        ; .. so we can't continue
  60.        ENDIF
  61. ;
  62. ;    Open a new window
  63. ;
  64.     WOPEN 0,0 23,79 (defa) Mail_Esc
  65.     ATSAY 0,2 (defa)   " BBS Mail "
  66.     ATSAY 23,25 (defa) " Press ESC to cancel BBMAINT "
  67. ;
  68. ;    Paint a new menu
  69. ;
  70. MAFI100:
  71.     CLEAR            ; Clear window
  72.     LOCATE 2,2
  73.  
  74.     MESS " 1) Clean up mail directory"
  75.     MESS " 2) Delete notes older than ..."
  76.     MESS " 3) Read notes newer than ..."
  77.     MESS " 4) Post a new note"
  78.     MESS "──────────────────────────────────── "
  79.     MESS "Note: Alt-Q to edit a file"
  80.     MESS "      Alt-F for a directory search"
  81.     MESS "      Alt-F10 to shell to DOS"
  82.     MESS " "
  83.     MESS "──────────────────────────────────── "
  84.     MESS " "
  85.     MESS "Select item (carriage return = previous): "
  86.     CURSOR N96,N95        ; Read current cursor
  87. ;
  88. ;    Wait for entry, and interpret
  89. ;
  90. MAFI200:
  91.     LOCATE N96 N95        ; Reposition cursor
  92.     KEYGET S0        ; Wait for it
  93.     SWITCH S0        ; Act according to keyget
  94.       CASE "1"
  95.            GOSUB ClrMail
  96.            GOTO MAFI100    ; Repaint after this
  97.            ENDCASE
  98.       CASE "2"
  99.            GOSUB DelMail
  100.            GOTO MAFI100    ; Repaint after this
  101.            ENDCASE
  102.       CASE "3"
  103.            GOSUB ReadMail
  104.            GOTO MAFI100    ; Repaint after this
  105.            ENDCASE
  106.       CASE "4"
  107.            GOSUB Compose
  108.            GOTO MAFI200    ; This sub saves screen
  109.            ENDCASE
  110.       CASE "0d"             ; c/r alone is exit
  111.            WCLOSE        ; Close window...
  112.            RETURN        ; and return to caller
  113.            ENDCASE
  114.       CASE "_NULL"          ; ESC -> Null
  115.            WCLOSE        ; Close window...
  116.            RETURN        ; Leave Main routine
  117.            ENDCASE
  118.       CASE "2100"           ; Alt-F
  119.            MANUAL "0x2100"  ; Perform Dir cmd
  120.            ENDCASE
  121.       CASE "1000"           ; Alt-Q
  122.            MANUAL "0x1000"  ; Edit a file
  123.            ENDCASE
  124.       CASE "7100"           ; Alt-F10
  125.            SHELL
  126.            DWINDOW 1,2,22,78; Reset dwindow after shell
  127.            LEGEND "_LEGEND" ; Redo the legend
  128.            ENDCASE
  129.       DEFAULT        ; None of the above
  130.            SOUND 100,100    ; Bronx cheer
  131.            ENDCASE
  132.       ENDSWITCH
  133.     GOTO MAFI200        ; Repaint screen and ask again
  134. ;
  135. ;    End of mail procedure
  136. ;
  137. Mail_Esc:
  138.     S0 = ""                 ; Fake a null entry
  139.     RETURN            ; Leave Mail routine
  140. ; -----------------------------------------------------------------------
  141. ; ----- ClrMail:  Clear mail directory of unneeded entries
  142. ;
  143. ClrMail:
  144.     FOPENI S24&"\BBS-Mail" TEXT
  145.     IF NOT SUCCESS        ; Open failed
  146.        S0 = "Error opening: "*S24&"\BBS-Mail"
  147.        GOSUB Error        ; Report
  148.        RETURN        ; And we're done
  149.        ENDIF
  150.  
  151.     FOPENO S24&"\TempMail" TEXT
  152.     IF NOT SUCCESS        ; Open failed
  153.        S0 = "Error opening: "*S24&"\TempMail"
  154.        GOSUB Error        ; Report
  155.        RETURN        ; And we're done
  156.        ENDIF
  157. ;
  158. ;    Initialize
  159. ;
  160.     CLEAR            ; Clear window
  161.     N9 = 0            ; Count recs written
  162. ;
  163. ;    Read loop (40 chars at a time to allow PRESERVE)
  164. ;
  165. CLMA100:
  166.     READ S10 40 N0        ; Read a record
  167.     IF EOF GOTO CLMA200    ; Skip on EOF
  168.     IF STRCMP S10(0:0) "*" GOTO CLMA115 ; Copy comments
  169.     IF ZERO N0 GOTO CLMA115 ; Copy blank lines
  170. ;
  171. ;    Test for the existence of the indicated file
  172. ;
  173. CLMA110:
  174.     S0 = S24&"\"*S10(25:37) ; Make a file name
  175.     IF NOT ISFILE S0    ; Test existence
  176.        MESS S0*" does not exist - deleting record"
  177.        GOTO CLMA130     ; Remove entry
  178.        ENDIF
  179.     MESS S0*" exists - copying record"
  180. ;
  181. ;    Count the write
  182. ;
  183. CLMA115:
  184.     INC N9            ; Count recs written
  185. ;
  186. ;    Copy record just read to output file
  187. ;
  188. CLMA120:
  189.     PRESERVE S10        ; Save !'s and ^'s
  190.     WRITE S10        ; Write text
  191.  
  192.     IF N0 LT 40        ; If we wrote end of record
  193.        WRITE "!"            ; Finish w/cr/lf
  194.        GOTO CLMA100     ; And continue copying
  195.        ENDIF
  196.     READ S10 40 N0        ; Read remainder of rec
  197.     IF NOT EOF GOTO CLMA120 ; Skip if not eof
  198.     WRITE "!"               ; Finish record
  199.     GOTO CLMA200        ; End of file
  200. ;
  201. ;    Throw away the current record
  202. ;
  203. CLMA130:
  204.     IF N0 LT 40 GOTO CLMA100
  205.     READ S10 40 N0         ; Read remainder of rec
  206.     IF NOT EOF GOTO CLMA130 ; Skip if not eof
  207. ;
  208. ;    We have end-of-file
  209. ;
  210. CLMA200:
  211.     WRITE "^Z"              ; Finish ASCII file
  212.     FCLOSEO         ; Close output
  213.     FCLOSEI         ; Close input
  214.     DELETE S24&"\BBS-Mail"  ; Delete original
  215.     RENAME S24&"\TempMail" S24&"\BBS-Mail"
  216.     IF ZERO N9 DELETE S24&"\BBS-Mail" ; Delete empty file
  217.     RETURN
  218. ; -----------------------------------------------------------------------
  219. ; ----- DelMail:  Delete mail files older than some date...
  220. ;    .. Note this only works through current and last year
  221. ;
  222. DelMail:
  223.     FOPENI S24&"\BBS-Mail" TEXT
  224.     IF NOT SUCCESS        ; Open failed
  225.        S0 = "Error opening: "*S24&"\BBS-Mail"
  226.        GOSUB Error        ; Report
  227.        RETURN        ; And we're done
  228.        ENDIF
  229.  
  230.     FOPENO S24&"\TempMail" TEXT
  231.     IF NOT SUCCESS        ; Open failed
  232.        S0 = "Error opening: "*S24&"\TempMail"
  233.        GOSUB Error        ; Report
  234.        GOTO DEMAErr     ; And we're done
  235.        ENDIF
  236.     N9 = 0            ; Counter for recs written
  237. ;
  238. ;    Initialize
  239. ;    .. (N2 = # days to keep, N3 = today's julian dayno, N4 = current yr)
  240. ;
  241.     S0 = "Enter age in days of the oldest file to keep"
  242.     GOSUB Get_Number    ; Ask for a value
  243.     IF FLAG(0) GOTO DEMAERR ; IF ESCAPE pressed...
  244.     IF N0 LE 0 N0 = 1    ; No negative dates
  245.     N2 = N0         ; Save value for later
  246.  
  247.     DATE S0 1        ; get current date (mm/dd/yyyy)
  248.     N4 = S0(6:9)        ; Save current year number
  249.     GOSUB Julian        ; make Julian date from current date
  250.     N3 = N0         ; Save current julian day number
  251.  
  252.     CLEAR            ; Clear window
  253. ;
  254. ;    Read loop (40 chars at a time to allow PRESERVE)
  255. ;
  256. DEMA100:
  257.     READ S10 40 N10     ; Read a record
  258.     IF EOF GOTO DEMA200    ; Skip on EOF
  259.     IF STRCMP S10(0:0) "*" GOTO DEMA115 ; Copy comments
  260.     IF ZERO N10 GOTO DEMA115; Copy blank lines
  261. ;
  262. ;    Test for the existence of the indicated file
  263. ;
  264. DEMA110:
  265.     S1 = S24&"\"*S10(25:37) ; Make a file name
  266.     IF NOT ISFILE S1    ; Test existence
  267.        MESS S1*" does not exist - cleaning dir"
  268.        GOTO DEMA130     ; Remove entry
  269.        ENDIF
  270. ;
  271. ;    Find the date of the file.  NOTE: The years we limit this code
  272. ;    .. to recognizing are the current and previous years.
  273. ;
  274.     FDATE S0 S1 1        ; Get the file's date into S0 (mm/dd/yyyy)
  275.     N5 = N4-S0(6:9)     ; Compute # years difference fdate and cur yr
  276.     IF N5 LT 0        ; If file year is future....
  277.        MESS S1*" date is in the fut